package ch.zhaw.swp1.model.message.address;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import ch.zhaw.swp1.model.message.validator.Validator;
import ch.zhaw.swp1.model.status.Status;
import ch.zhaw.swp1.model.status.error.MessageSenderError;

/**
 * Generic class representing an address
 * @author Daniel Tiefenauer
 */
public abstract class Address implements Validator, Serializable {

	/**
	 * Default version
	 */
	private static final long serialVersionUID = 1L;
	protected String address = "";
	protected List<Status> statusList = new ArrayList<Status>();

	/************************************************************************************/
	/* Constructors
	/*----------------------------------------------------------------------------------*/
	/**
	 * Default constructor
	 */
	public Address() {
	}

	/**
	 * Overloaded Constructor with address
	 * @param address String containing the address
	 */
	public Address(String address) {
		this.address = address.trim();
	}
	
	/************************************************************************************/
	/* Methods
	/*----------------------------------------------------------------------------------*/
	/**
	 * Override string representation
	 */
	@Override
	public final String toString(){
		return address;
	}
	
	/**
	 * Get  list of current stati
	 * @return a list of status objects
	 */
	public List<Status> getStatusList(){
		validate();
		return statusList;
	}

	/************************************************************************************/
	/* START Validation
	/*----------------------------------------------------------------------------------*/
	/**
	 * Generic validation method. All subclasses must call this method via super.validate()
	 * if they override the method!
	 */
	public List<Status> validate(){
		statusList.clear();
		if(address.isEmpty()){
			statusList.add(new MessageSenderError());
		}
		return statusList;
	}
	
	/**
	 * Check if address is valid
	 * @return true if the address is valid, false if not
	 */
	public boolean isValid(){
		validate();
		return statusList.isEmpty();
	}
	
	/************************************************************************************/
	/* START Setters/Getters
	/*----------------------------------------------------------------------------------*/
	public final String getAddress() {
		return address;
	}
	public final void setAddress(String address) {
		this.address = address;
	}
	/*----------------------------------------------------------------------------------*/
	/* END Setters/Getters
	/************************************************************************************/

}
